package com.ruoyi.store.controller;

import java.util.List;

import com.ruoyi.store.service.ITotalMoneyService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.store.domain.TotalMoney;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 汇总报Controller
 * 
 * @author ruoyi
 * @date 2023-05-02
 */
@Controller
@RequestMapping("/store/money")
public class TotalMoneyController extends BaseController
{
    private String prefix = "store/money";

    @Autowired
    private ITotalMoneyService totalMoneyService;

    @RequiresPermissions("store:money:view")
    @GetMapping()
    public String money()
    {
        return prefix + "/money";
    }

    /**
     * 查询汇总报列表
     */
    @RequiresPermissions("store:money:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TotalMoney totalMoney)
    {
        startPage();
        List<TotalMoney> list = totalMoneyService.selectTotalMoneyList(totalMoney);
        return getDataTable(list);
    }

    /**
     * 导出汇总报列表
     */
    @RequiresPermissions("store:money:export")
    @Log(title = "汇总报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TotalMoney totalMoney)
    {
        List<TotalMoney> list = totalMoneyService.selectTotalMoneyList(totalMoney);
        ExcelUtil<TotalMoney> util = new ExcelUtil<TotalMoney>(TotalMoney.class);
        return util.exportExcel(list, "汇总报数据");
    }

    /**
     * 新增汇总报
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存汇总报
     */
    @RequiresPermissions("store:money:add")
    @Log(title = "汇总报", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TotalMoney totalMoney)
    {
        return toAjax(totalMoneyService.insertTotalMoney(totalMoney));
    }

    /**
     * 修改汇总报
     */
    @RequiresPermissions("store:money:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TotalMoney totalMoney = totalMoneyService.selectTotalMoneyById(id);
        mmap.put("totalMoney", totalMoney);
        return prefix + "/edit";
    }

    /**
     * 修改保存汇总报
     */
    @RequiresPermissions("store:money:edit")
    @Log(title = "汇总报", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TotalMoney totalMoney)
    {
        return toAjax(totalMoneyService.updateTotalMoney(totalMoney));
    }

    /**
     * 删除汇总报
     */
    @RequiresPermissions("store:money:remove")
    @Log(title = "汇总报", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(totalMoneyService.deleteTotalMoneyByIds(ids));
    }
}
